package main

import (
	"flag"
	"fmt"
	"os"
	"path/filepath"

	"github.com/BurntSushi/toml"
)

var (
	settings Settings
)

type Settings struct {
	Debug      bool
	HostConfig string
	RemoteDns  string
	LocalHost  string
	LogFile    string
}

func init() {

	var configFile string
	dirpath, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	default_conf := filepath.Join(dirpath, "tadns.conf")
	flag.StringVar(&configFile, "c", default_conf, "Look for godns toml-formatting config file in this directory")
	flag.Parse()

	if _, err := toml.DecodeFile(configFile, &settings); err != nil {
		fmt.Printf("%s is not a valid toml config file\n", configFile)
		fmt.Println(err)
		os.Exit(1)
	}
}
